home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / xconf / section1.c < prev    next >
C/C++ Source or Header  |  1995-02-12  |  1KB  |  69 lines

  1. #include <string.h>
  2. #include <stdlib.h>
  3. #include "xconf.h"
  4. #include "section.h"
  5.  
  6.  
  7.  
  8. /*
  9.     Make a copy of itself
  10. */
  11. PUBLIC VIRTUAL SECTION *SECTION::clone() const
  12. {
  13.     SECTION *ret = new SECTION (name);
  14.     if (ret != NULL){
  15.         for (int i=0; i<getnb(); i++){
  16.             ret->add (getitem(i)->clone());
  17.         }
  18.     }
  19.     return ret;
  20. }
  21.  
  22.  
  23. #if 0
  24. /*
  25.     Add/merge a SECTION into another
  26.     Section and their content are added to the destination
  27. */
  28. PUBLIC void SECTION::merge (const SECTION *src)
  29. {
  30.     OPTION::merge (src);
  31.     OPTION **tbsrc = src->tbvalues;
  32.     int nbsrc = src->nbvalues;
  33.     OPTION **tbdst = tbvalues;
  34.     int nbdst = nbvalues;
  35.     for (int i=0; i<nbsrc; i++){
  36.         const OPTION *optsrc = tbsrc[i];
  37.         for (int j=0; j<nbdst; j++){
  38.             OPTION *optdst = tbdst[i];
  39.             if (strcmp(optdst->keyw,optsrc->keyw)==0){
  40.                 optdst->merge (optsrc);                
  41.                 break;
  42.             }
  43.         }
  44.         if (j == nbdst){
  45.             // The section must simply be copied
  46.             addoption (optsrc->clone());
  47.         }
  48.     }
  49. }
  50. #endif
  51.  
  52. /*
  53.     Locate the value of an item identified with keyw
  54.     Return NULL if not found.
  55. */
  56. PUBLIC const char *SECTION::findarg (const char *keyw)
  57. {
  58.     const char *ret = NULL;
  59.     for (int i=0; i<getnb(); i++){
  60.         const OPTION *opt = getitem(i);
  61.         if (strcmp(opt->keyw,keyw)==0){
  62.             ret = opt->arg;
  63.             break;
  64.         }
  65.     }
  66.     return ret;
  67. }
  68.  
  69.